package org.example.platerecognize;

import org.example.platerecognize.base.ColorEnum;
import org.example.platerecognize.base.LayoutEnum;
import org.example.platerecognize.dao.PlateData;

import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Zhou
 * @date 14:27 2024/7/16
 */
public final class PlateInfoWrapper {
    public static List<PlateVO> wrapPlateResult(List<PlateData> plateDatas, String base64) {
        List<PlateVO> plateResults = new ArrayList<>();
        if(null != plateDatas && !plateDatas.isEmpty()){
            for(PlateData plateData : plateDatas){

                var points = Arrays.stream(plateData.box.points())
                        .map(e -> new Point((int) e.x, (int) e.y)).toList();
                PlateVO.PlateLocation location = new PlateVO.PlateLocation(points);

                var plateInfo2 = new PlateVO.PlateInfo2(ColorEnum.of(plateData.parseInfo.plateColor), plateData.parseInfo.plateNo);

                PlateVO plateResult = new PlateVO();
                plateResult.setScore((float)Math.floor(plateData.score * 1000000)/10000);
                plateResult.setLocation(location);
                plateResult.setPlateInfo(plateInfo2);
                plateResult.setLayout(plateData.single? LayoutEnum.SINGLE:LayoutEnum.SINGLE_LW);
                plateResult.setPictureBase64(base64);
                plateResults.add(plateResult);
            }
        }
        return plateResults;
    }
}
